package com.txsj.scan.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.txsj.scan.R;
import com.txsj.scan.bean.AllocationApplyDetailsBean;
import com.txsj.scan.utils.glide.GlideImgManager;

import java.util.List;

public class AllocationApplyGoodsAdapter extends RecyclerView.Adapter {

    List<AllocationApplyDetailsBean.DetailsBean> goodsList;
    Context mContext;
    LayoutInflater inflater;

    public AllocationApplyGoodsAdapter(Context context) {
        this.mContext = context;
        inflater = LayoutInflater.from(context);
    }


    public void setGoodsList(List<AllocationApplyDetailsBean.DetailsBean> goodsList) {
        this.goodsList = goodsList;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new GoodsLisHolder(inflater.inflate(R.layout.item_allocation_goods, parent, false));
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, int position) {
        GoodsLisHolder holder = (GoodsLisHolder) viewHolder;
        AllocationApplyDetailsBean.DetailsBean mGoods = goodsList.get(position);
        GlideImgManager.getLoadImg(mContext, mGoods.getGoods_img(), holder.iv_goods_img);
        holder.tv_goods_name.setText(mGoods.getGoods_name());
        if(mGoods.getGoods_num() != null){
            holder.tv_goods_num.setText(mGoods.getGoods_num()+"");
        }

        holder.tv_goods_nowKuCun.setText("当前库存：" + mGoods.getPast_inventory());
        holder.tv_goods_sales.setText("日均销量：" + mGoods.getPast_sales_volume());
        holder.tv_goods_count.setText(mGoods.getGoods_count()+"");

    }

    @Override
    public int getItemCount() {
        if (goodsList != null && goodsList.size() > 0)
            return goodsList.size();
        return 0;
    }

    class GoodsLisHolder extends RecyclerView.ViewHolder {

        ImageView iv_goods_img;
        TextView tv_goods_name;
        TextView tv_goods_num;
        TextView tv_goods_nowKuCun;
        TextView tv_goods_sales;
        TextView tv_goods_count;

        public GoodsLisHolder(View itemView) {
            super(itemView);
            iv_goods_img = itemView.findViewById(R.id.iv_goods_img);
            tv_goods_name = itemView.findViewById(R.id.tv_goods_name);
            tv_goods_num = itemView.findViewById(R.id.tv_goods_num);
            tv_goods_nowKuCun = itemView.findViewById(R.id.tv_goods_nowKuCun);
            tv_goods_sales = itemView.findViewById(R.id.tv_goods_sales);
            tv_goods_count = itemView.findViewById(R.id.tv_goods_count);
        }
    }
}
